<?php

class Controller_Post
{
    var $_modelPosts;
    function Controller_Post()
    {
        $this->_modelPosts =& FLEA::getSingleton('Model_Posts');
    }
    function actionIndex()
    {
        
        $posts = $this->_modelPosts->findAll();

        include('APP/View/PostIndex.php');
    }
    function actionAdd()
    {
        include('APP/View/PostAdd.php');
    }

    function actionSave()
    {
        $data = array(
            'title' => $_POST['title'],
            'body' => $_POST['content']
        );
        $this->_modelPosts->save($data);
        redirect(url('Post', 'Index'));
    }

    function actionView()
    {
        $id = (int)$_GET['id'];
        $post = $this->_modelPosts->find($id);
		$smarty->assign('id', $post['id']);
		$smarty->display('common/index.html');
       // include('APP/View/PostView.php');
    }

    function actionDelete()
    {

        $id = (int)$_GET['id'];
        $post = $this->_modelPosts->removeByPkv($id);
        redirect(url('Post', 'Index'));
    }
}
